﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BookTransactionControllers.Services;
using BookTransactionControllers.Connection;
using BookTransactionModels;
using System.Data;
using System.Data.SqlClient;

namespace BookTransactionControllers.Services_Impl
{
    public class UserManagerImpl : IUserServices, IMainServices
    {
        public bool Insert(UserBean user)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "Insert into [User]([ID],[FullName],[Password]) Values(@ID,@FullName, @Password)";
            command.Parameters.AddWithValue("FullName",user.FullName);
            command.Parameters.AddWithValue("Password",user.Password);
            command.Parameters.AddWithValue("ID",user.ID);
            return Connect.ExcuteNonQuery(command);
        }

        public String[] CheckLogin(string Email, string Password)
        {
            String[] info = new String[2];
            SqlCommand command = new SqlCommand();
            command.CommandText = "Select [ID],[FullName] From [User] Where [Email]=@Email and [Password]=@Password";
            command.Parameters.AddWithValue("@Email", Email);
            command.Parameters.AddWithValue("@Password", Password);
            DataTable tblLogin = Connect.ExcuteQuery(command, "tblLogin");
            if (tblLogin.Rows.Count == 1)
            {
                info[0] = tblLogin.Rows[0][0].ToString();
                info[1] = tblLogin.Rows[0][1].ToString();
            }
            else
            {
                info = null;
            }
            return info;
        }

        public bool Delete(SqlCommand command)
        {
            return Connect.ExcuteNonQuery(command);
        }

        public DataTable SelectTable(SqlCommand command, String tblName)
        {
            throw new NotImplementedException();
        }

        public bool Update(SqlCommand command)
        {
            throw new NotImplementedException();
        }
    }
}
